<admintpl file="header" />

</head>

<body>

<div class="wrap">

    <ul class="nav nav-tabs">
       <li><a href="{:U('Qrcode/AdminQrcode/index')}">红包管理</a></li>
        <li class="active"><a href="{:U('Qrcode/AdminQrcode/showrecharge')}">充值</a></li>
    </ul>

    <div>
        <form class="well form-search" method="post" action="{:U('Qrcode/AdminQrcode/showrecharge')}">

            <input type="text" name="name" value="" placeholder="请输入公司名称">&nbsp;

            <input type="submit" class="btn btn-primary" value="搜索" />

        </form>

        <div class="tab-content">
            <div class="tab-pane active" id="one">
                <table class="table table-bordered table-striped table-hover">
                    <thead>
                    <tr>
                        <th>ID</th>
                        <th>公司名称</th>
                        <th>余额</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                        <if condition="$list">
                            <foreach name="list" item="vo">
                                <tr>
                                    <td>{$vo.uid}</td>
                                    <td>{$vo.name}</td>
                                    <!--<td>{$vo.users_blance.user_company_blance}</td>-->
                                    <td id="{$vo.uid}_blance">{$vo.users_blance.user_company_blance}</td>
                                    <td>
                                        <a href="javascript:void(0);" onclick="showewm({$vo.uid},'{$vo.name}');">充值</a>
                                        <a href="javascript:void(0);" onclick="cash({$vo.uid},'{$vo.name}');">返现</a>
                                    </td>
                                </tr>
                            </foreach>
                            <else/>
                            <tr><td colspan="6">
                                <span class="text-info">暂时没有记录</span>
                            </td></tr>
                        </if>
                    </tbody>
                </table>
                <div class="pagination">{$page}</div>
            </div>
        </div>

    </div>

</div>

<script src="__PUBLIC__/js/common.js"></script>

<script>
    function showewm(uid,name) {

        var http = window.location.protocol;

        var host = window.location.host;

        //var url  = escape(http+'//'+host+'/index.php?g=qrcode&m=company&a=index&id='+id+'&code='+code);
        var url  = escape(http+'//'+host+'/index.php');

        console.log(url);

        Wind.use("artDialog",function(){

            art.dialog({

                title: '充值金额',

                fixed: true,

                width:"300px",

                height: '200px',

                id:"image_priview",

                lock: false,

                background:"#CCCCCC",

                opacity:0,

                //content: name+'<form action="/sy/Qrcode/AdminQrcode/recharge" method="post">' +
                content: name+'<form>' +
                    '充值：' +
                    '<input id="blance_recharge" name="userCompanyBlance" type="text" />'+
                    '元'+
                    '<input id="id_recharge" name="uid" type="hidden" value='+uid+'>'+
                '</form>',
                
                ok:function (e) {
                    rechargeAjax();
                }
            });
        });
    }

    function rechargeAjax(){
        var blance=$("#blance_recharge").val();
        var uid=$("#id_recharge").val();

        var data = {userCompanyBlance: blance, uid : uid};
        $.getJSON("{:U('Qrcode/AdminQrcode/recharge')}", data, function(response) {
            if(response.state=='success'){
                var blance=response.content;

                var oldValue=$('#'+uid+'_blance').text();
                var newValue=(parseFloat(oldValue)+parseFloat(blance)/100).toFixed(2);
                $('#'+uid+'_blance').text(newValue);
            }else{
                alert(response.content);
            }
        });
    }

    function cash(uid,name){
        var http = window.location.protocol;

        var host = window.location.host;

        //var url  = escape(http+'//'+host+'/index.php?g=qrcode&m=company&a=index&id='+id+'&code='+code);
        var url  = escape(http+'//'+host+'/index.php');

        console.log(url);

        Wind.use("artDialog",function(){

            art.dialog({

                title: '返现金额',

                fixed: true,

                width:"300px",

                height: '200px',

                id:"image_priview",

                lock: false,

                background:"#CCCCCC",

                opacity:0,

                content: name+'<form>' +
                '返现：' +
                '<input id="amount_cash" name="amount" type="text" />'+
                '元'+
                '<input id="uid_cash" name="uid" type="hidden" value='+uid+'>'+
                '</form>',
                ok:function (e) {
                    cashAjax();
                }
            });
        });
    }

    function cashAjax() {
        /*var amount=document.getElementById('amount_cash').value;
        var uid=document.getElementById('uid_cash').value;

        var xmlhttp;
        if(window.XMLHttpRequest){
            xmlhttp=new XMLHttpRequest();
        }else{
            xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');
        }

        xmlhttp.onreadystatechange=function () {
            if(xmlhttp.readyState==4&& xmlhttp.status==200){
                var obj=eval("(" + xmlhttp.response + ")");

                var oldValue= document.getElementById(uid+'_blance').innerHTML;
                var newValue=(parseFloat(oldValue)-parseFloat(obj.amount)).toFixed(2);
                document.getElementById(uid+'_blance').innerText=newValue;
            }
        }

        xmlhttp.open('POST','{:U(\'Qrcode/AdminQrcode/cash\')}',true);
        xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        xmlhttp.send('amount='+amount+'&uid='+uid);*/

        var amount=$("#amount_cash").val();
        var uid=$("#uid_cash").val();

        var data = {amount: amount, uid : uid};
        $.getJSON("{:U('Qrcode/AdminQrcode/cash')}", data, function(response) {
            if(response.state=='success'){
                var amount=response.content;

                var oldValue=$('#'+uid+'_blance').text();
                var newValue=(parseFloat(oldValue)-parseFloat(amount)).toFixed(2);
                $('#'+uid+'_blance').text(newValue);
            }else{
                alert(response.content);
            }
        });

    }

</script>

</body>

</html>